//
//  AreaViewController.m
//  GXWN
//
//  Created by iMacOne on 15/11/5.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "AreaViewController.h"
#import "FSDropDownMenu.h"
#import "Size.h"
#import "General.h"
#import "ToolUtil.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface AreaViewController ()
@property (nonatomic, strong)MKMapView * mapView;

@end

@implementation AreaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
//    [General initialization:self isPoint:YES];
//    self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
//    _mapView.showsUserLocation = YES;
//    _mapView.zoomEnabled = YES;
//    NSLog(@"kaka1 %@",[General shareGeneral].point);
//    CLLocationCoordinate2D pos = {37.785834,-122.406417};
//    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(pos,2000, 2000);//以pos为中心，显示2000米
//    MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];//适配map view的尺寸
//    [_mapView setRegion:adjustedRegion animated:YES];
//    [self.view addSubview:_mapView];
    
    [self createTitle:@"lala" midTitle:@"地区"];
    [ToolUtil createLine:margin_64 superView:self.view lift:0 width:WindowWidth hight:0.5 color:[UIColor grayColor]];
    
   
    self.countryArray = @[@"中国",@"美国",@"英国"];
    self.cityArray = @[@[@"浙江",@"北京",@"安徽"],@[@"洛杉矶",@"丹佛",@"克利夫兰"],@[@"伦敦",@"曼城",@"伯明翰"],];
//    NSLog(@"aa%@",self.countryArray);
    _currentCityArray = _cityArray[0];
    FSDropDownMenu *menu = [[FSDropDownMenu alloc] initWithOrigin:CGPointMake(0, 90) andHeight:300 ];
    menu.backgroundColor = [UIColor yellowColor];
    menu.tag = 1001;
//    UIButton *activityBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 70, 62, 30)];
//    activityBtn.backgroundColor = DEBUG_CLOLR;
//    [activityBtn addTarget:self action:@selector(btnPressed) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:activityBtn];
//    [self btnPressed];
//    [menu menuTapped];

    menu.delegate = self;
    menu.dataSource = self;
    [self.view addSubview:menu];
    
    
    
    
    
    // Do any additional setup after loading the view.
}

-(void)btnPressed{
    FSDropDownMenu *menu = (FSDropDownMenu*)[self.view viewWithTag:1001];
    [UIView animateWithDuration:0.2 animations:^{
        
    } completion:^(BOOL finished) {
        [menu menuTapped];
    }];
}
- (NSInteger)menu:(FSDropDownMenu *)menu tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == menu.rightTableView) {
        return _currentCityArray.count;
    }else{
        return _countryArray.count;
    }
}
- (NSString *)menu:(FSDropDownMenu *)menu tableView:(UITableView*)tableView titleForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == menu.rightTableView) {
        
        return _currentCityArray[indexPath.row];
    }else{
        return _countryArray[indexPath.row];
    }
}
- (void)menu:(FSDropDownMenu *)menu tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(tableView == menu.leftTableView){
        _currentCityArray = _cityArray[indexPath.row];
        NSLog(@"laa");
        [menu.rightTableView reloadData];
    }else{
//        [self resetItemSizeBy:_currentCityArray[indexPath.row]];
        NSLog(@"ww");
        
    }
    
}
#pragma mark - reset button size

-(void)resetItemSizeBy:(NSString*)str{
    UIButton *btn = (UIButton*)self.navigationItem.rightBarButtonItem.customView;
    [btn setTitle:str forState:UIControlStateNormal];
    NSDictionary *dict = @{NSFontAttributeName:btn.titleLabel.font};
    CGSize size = [str boundingRectWithSize:CGSizeMake(150, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    btn.frame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y,size.width+33, 30);
    btn.imageEdgeInsets = UIEdgeInsetsMake(11, size.width+23, 11, 0);
}

@end
